------------------------------
-- VeniScript 2             --
-- PubGamer                 --
-- Scripting:               --
-- Rick Dark                --
-- Waffler                  --
-- ReichRP Scripting Team   --
-- Kahn                     --
------------------------------

--[[

	8:33 PM - [PubGamer] Michael: Not enough weapons can fit inside the things in the armory
	Need to fit more radios too
	Fix te bug where your team doesnt set
	Put close buttons on all the char create things
	8:33 PM - Waffler: i will save them in the script so i know
	
	-- one week later I havn't done them yet so SUCK MY DICK.
	
--]]

DeriveGamemode( "Gear" );
DeriveGamemode( "sandbox" );

function CreatePlayerTables()

	sql.Query( "CREATE TABLE IF NOT EXISTS characters ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, SteamID TEXT, RPName TEXT, Model TEXT, Tokens INTEGER, CID INTEGER, Age INTEGER, Title TEXT, SecondTitle TEXT, containers TEXT, Items TEXT, Loan INTEGER, ClassMark TEXT, Faction TEXT, CharFlags TEXT );" );
	
end

CreatePlayerTables()

function CreateUserTables()

	sql.Query( "CREATE TABLE IF NOT EXISTS users ( userid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, SteamID TEXT, UserName TEXT, PlayerFlags TEXT, HasToolTrust TEXT, CanDupe TEXT );" );
	
end	

CreateUserTables()

GM.Name = "TacoScript 2";

--require( "ts2" );
AddCSLuaFile( "cl_scoreboard.lua" );
AddCSLuaFile( "cl_init.lua" );
AddCSLuaFile( "shared.lua" );
AddCSLuaFile( "cl_hud.lua" );
AddCSLuaFile( "cl_radiochat.lua" );
AddCSLuaFile( "cl_umsg.lua" );
AddCSLuaFile( "cl_chat.lua" );
AddCSLuaFile( "cl_playermenu.lua" );
AddCSLuaFile( "player_shared.lua" );
AddCSLuaFile( "cl_charactermenu.lua" );
AddCSLuaFile( "cl_accountcreation.lua" );
AddCSLuaFile( "cl_business.lua" );
AddCSLuaFile( "cl_inventory.lua" );
AddCSLuaFile( "cl_dev.lua" );
AddCSLuaFile( "cl_weaponselect.lua" );
AddCSLuaFile( "entity_shared.lua" );
AddCSLuaFile( "cl_admin.lua" );
AddCSLuaFile( "cl_storage.lua" );
AddCSLuaFile( "cl_help.lua" );
AddCSLuaFile( "cl_update.lua" );
AddCSLuaFile( "cl_weather.lua" );
AddCSLuaFile( "cl_openingscreen.lua" );
AddCSLuaFile( "factions.lua" );

--AddCSLuaFile( "BananaVGUI/panel.lua" );
--AddCSLuaFile( "BananaVGUI/scrolling.lua" );

include( "shared.lua" );
include( "player_bools.lua" );
include( "player_util.lua" );
include( "player_chat.lua" );
include( "player_inventory.lua" );
include( "player_connection.lua" );
include( "player_hooks.lua" );
include( "player_update.lua" );
include( "player_shared.lua" );
include( "player_sounds.lua" );
include( "server_hooks.lua" );
include( "server_events.lua" );
include( "server_scanner.lua" );
include( "server_util.lua" );
include( "chat_commands.lua" );
include( "con_commands.lua" );
include( "engine_concmds.lua" );
include( "animation_tables.lua" );
include( "animations.lua" );
include( "resources.lua" );
include( "action_menu.lua" );
include( "player_save.lua" );
include( "process_bar.lua" );
include( "admin_concmds.lua" );
include( "entity_shared.lua" );
include( "map_parsing.lua" );
include( "storage.lua" );
include( "wholesale.lua" );
include( "blackmarket.lua" );
include( "contraband.lua" );
include( "door_ownership.lua" );
include( "factions.lua" );

-- Is this really necessary?
for k, v in pairs( player.GetAll() ) do

	GAMEMODE:PlayerInitialSpawn( v );

end

include( "items/item_includes.lua" );
include( "items/item_interaction.lua" );

if( TS2InitializedOnce ) then
	GAMEMODE:InitPostEntity();
end

TS.MOTD = "Hello and Welcome to PubGamer Serious Roleplay\n\nThis is Serious roleplay, so you are expected to act in a serious manner.\n\n By clicking done you accept the terms and conditions located here\n\n http://www.pubgamer.org/forums/viewtopic.php?f=3&t=28\n\n Failure to comply with these rules will get you kicked/banned indefinetely.\n- Roleplay properly or dont play at all\n- Respect admins. Follow what they say.\n- If you have a problem with an admin, report it on the forum.\n\n Thankyou for taking the time to read this.\n Please report all bugs and problems on our forums.\n Please enjoy your experience at PubGamer.\n\n Regards\n PubGamer Administration\n\n www.pubgamer.org  ";

TS.MakeDirectoryExist( "TS2" );
TS.MakeDirectoryExist( "TS2/mapdata" );

timer.Simple( 2, TS.CreateThirdPersonCamera );

game.ConsoleCommand( "mp_falldamage 1\n" );

--Some Gear hooks aren't needed.
hook.Remove( "SetPlayerAnimation", "GearSetPlayerAnimation" );
hook.Remove( "PlayerSay", "GearPlayerSay" );
hook.Remove( "PlayerSpawn", "GearPlayerSpawn" );

PostGamemodeLoad();

--GM.Admins = { }

-----------------------------------
-- Admins List                   --
-- Waffler: STEAM_0:1:17476605   --
-- do this later lol             --
-----------------------------------
--GM.Admins["STEAM_0:1:17476605"] = "C"
-----------------------------------

if( not TS2InitializedOnce ) then

	local fileread = file.Read;
	function file.Read( dir )
	
		if( string.find( dir, "gamemodes" ) or
			string.find( dir, "lua" ) ) then
			
			return "";
			
		end
		
		return fileread( dir );
	
	end

end

storm_active = false;

function AutoWeather()

	if( storm_active ) then return; end
	
	if( math.random( 1, 3 ) == 1 ) then
		BeginStorm();
	end	
	
end
timer.Create( "AutoWeather", 2400, 0, AutoWeather );

function GenerateCombineRadio()
	
	TS.CombineRadioFreq = 0;
		
	TS.CombineRadioFreq = tonumber( math.random( 1, 999 ) .. "." .. math.random( 0, 9 ) );
	
end
timer.Simple( 5, GenerateCombineRadio );

function PeriodicSave()
	
	for k, v in pairs( player.GetAll() ) do
	
		if( v:GetTable().Initialized and not v:GetTable().CharCreateMenu ) then
			v:UpdateCharacter();
		end
	
	end
	
	TS.PrintMessageAll( 3, "[TacoScript2]: Saving all characters" );
	
end
timer.Create( "PeriodicSave", 600, 0, PeriodicSave );


